<?php
/*
 * $id:admin/includes/classes/productImageHandler.php
 *
 * oscProductImage version 2.0
 *
 * Copyright 2011, Zaenal Muttaqin
 * http://blog.lokamaya.net - http://lokamaya.com
 *
 * Licensed under the MIT license:
 * http://creativecommons.org/licenses/MIT/
 *
 */
  include_once(DIR_WS_LANGUAGES . $language . '/opi_productimage.php');

  //AUTO-INSTALL
  if (!defined('OSC_PRODUCT_IMAGE_MODULE')) {
      define('OSC_PRODUCT_IMAGE_ABSOLUTE_PATH', DIR_FS_CATALOG_IMAGES);
      define('OSC_PRODUCT_IMAGE_RELATIVE_DIRECTORY', 'products');
      define('OSC_PRODUCT_IMAGE_THUMBNAIL_DIRECTORY', '_thumbnail_');
      define('OSC_PRODUCT_IMAGE_DIRECTORY_PRIVILEGE', '1');
      define('OSC_PRODUCT_IMAGE_DELETE_PRIVILEGE', '1');
      define('OSC_PRODUCT_IMAGE_ALLOWED_EXTENSIONS', 'gif|jpg|jpeg|png');
      define('OSC_PRODUCT_IMAGE_CLEANUP', 'false');
      
      @tep_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title,configuration_key,configuration_value,configuration_description,configuration_group_id,sort_order,date_added, set_function) VALUES ('OPI: Version', 'OSC_PRODUCT_IMAGE_MODULE', '2.0', 'Ultimate OsC Product Image Module with Ajax and Auto-Thumbnail', '6', '0', NOW(), null),  ('OPI: Updater', 'OSC_PRODUCT_IMAGE_MODULE_UPDATER', '" . tep_db_input(time()) . "', 'For updater purpose', '6', '0', NOW(), null),  ('OPI: debuger', 'OSC_PRODUCT_IMAGE_MODULE_DEBUGER', '', 'For debuger purpose', '6', '0', NOW(), null), ('OPI: Absolute Path', 'OSC_PRODUCT_IMAGE_ABSOLUTE_PATH', '" . tep_db_input(OSC_PRODUCT_IMAGE_ABSOLUTE_PATH) . "', 'OsC Product Image Module: absolute path.<br /><br />If empty, it will use catalog image path DIR_FS_CATALOG_IMAGES.<br /><br />', '4', '250', NOW(), null), ('OPI: Relative Directory', 'OSC_PRODUCT_IMAGE_RELATIVE_DIRECTORY', '" . tep_db_input(OSC_PRODUCT_IMAGE_RELATIVE_DIRECTORY) . "', 'OsC Product Image Module: relative to OPI: Absolute Path.<br />', '4', '255', NOW(), null), ('OPI: Thumbnail Directory', 'OSC_PRODUCT_IMAGE_THUMBNAIL_DIRECTORY', '" . tep_db_input(OSC_PRODUCT_IMAGE_THUMBNAIL_DIRECTORY) . "', 'OsC Product Image Module: Thumbnail directory, relative to OPI: Absolute Path.<br /><br />Please make sure you create directory manually and add underscore to it (example: _thumbnail_).<br /><br />', '4', '257', NOW(), null), ('OPI: Create Directory', 'OSC_PRODUCT_IMAGE_DIRECTORY_PRIVILEGE', '" . tep_db_input(OSC_PRODUCT_IMAGE_DIRECTORY_PRIVILEGE) . "', 'OsC Product Image Module: admin privileges for creating new directory. <br /><br />Comma separated admin id that have privilege to create directory. Leave empty to allow all admin.<br /><br />', '4', '261', NOW(), null), ('OPI: Delete Image', 'OSC_PRODUCT_IMAGE_DELETE_PRIVILEGE', '" . tep_db_input(OSC_PRODUCT_IMAGE_DELETE_PRIVILEGE) . "', 'OsC Product Image Module: admin privileges for deleting image from server. <br /><br />Comma separated admin id that have privilege to delete image. Leave empty to allow all admin.<br /><br />', '4', '262', NOW(), null), ('OPI: Allowed Extension', 'OSC_PRODUCT_IMAGE_ALLOWED_EXTENSIONS', '" . tep_db_input(OSC_PRODUCT_IMAGE_ALLOWED_EXTENSIONS) . "', 'OsC Product Image Module: allowed extension. <br /><br />Divisor separated extension. Default gif|jpg|jpeg|png<br /><br />', '4', '263', NOW(), null), ('OPI: Cleanup Thumbnail', 'OSC_PRODUCT_IMAGE_CLEANUP', 'false', 'OsC Product Image Module: Cleanup Thumbnail Folder. <br />', '4', '264', NOW(), '" . tep_db_input("tep_cfg_select_option(array('true', 'false'), ") . "')");      
      if (@tep_db_query("ALTER TABLE " . TABLE_PRODUCTS . " ADD products_images TEXT NULL DEFAULT '' AFTER products_image")) {
          @tep_db_query("UPDATE " . TABLE_PRODUCTS . " p SET p.products_images=(SELECT largeimage FROM (SELECT l.products_id, group_concat( l.image SEPARATOR ',' ) as largeimage FROM " . TABLE_PRODUCTS_IMAGES . " l GROUP BY l.products_id) as tableLarge WHERE tableLarge.products_id=p.products_id)");
          @tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET products_images=CONCAT_WS(',', products_image, products_images)");
      }
  } elseif (OSC_PRODUCT_IMAGE_MODULE == '1.0') {
      //AUTO UPGRADE: from 1.0 to 2.0
      define('OSC_PRODUCT_IMAGE_MODREWRITE', 'true');
      @tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='2.0' WHERE configuration_key='OSC_PRODUCT_IMAGE_MODULE'");
      @tep_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title,configuration_key,configuration_value,configuration_description,configuration_group_id,sort_order,date_added, set_function) VALUES ('OPI: mod_rewrite enabled', 'OSC_PRODUCT_IMAGE_MODREWRITE', 'true', 'OsC Product Image Module: If mod_rewrite enable, set to true. Otherwise, set to false. <br />', '4', '264', NOW(), '" . tep_db_input("tep_cfg_select_option(array('true', 'false'), ") . "')");
  }
  

  class productImageHandler {
    private $options, $directories, $error, $output, $action, $json, $template, $chmods;
    
    function __construct($options=null, $pInfoProductsImages='') {
        $extension = tep_not_null(trim(OSC_PRODUCT_IMAGE_ALLOWED_EXTENSIONS)) ? trim(OSC_PRODUCT_IMAGE_ALLOWED_EXTENSIONS) : 'gif|jpg|jpeg|png';
        $path      = tep_not_null(trim(OSC_PRODUCT_IMAGE_ABSOLUTE_PATH)) ? trim(OSC_PRODUCT_IMAGE_ABSOLUTE_PATH) : DIR_FS_CATALOG_IMAGES;
        $relative  = tep_not_null(trim(OSC_PRODUCT_IMAGE_RELATIVE_DIRECTORY)) ? preg_replace(array('@[\/\\\]+@', '@^[\/]@', '@[\/]$@'), array("/", "", ""), trim(OSC_PRODUCT_IMAGE_RELATIVE_DIRECTORY)) . '/' : '';
        $thumbdir  = tep_not_null(trim(OSC_PRODUCT_IMAGE_THUMBNAIL_DIRECTORY)) ? preg_replace(array('@[\/\\\]+@', '@^[\/]@', '@[\/]$@'), array("/", "", ""), trim(OSC_PRODUCT_IMAGE_THUMBNAIL_DIRECTORY)) . '/' : '';
        
        $this->options = array(
            'script_url' => $_SERVER['PHP_SELF'],
            'upload_dir' => $path,
            'relative_dir' => $relative, 
            'thumbnail_dir' => $thumbdir, 
            'max_file_size' => null, // The php.ini settings upload_max_filesize and post_max_size
            'extensions' => $extension
        );
        
        if ($options) {
            $this->options = array_merge($this->options, $options);
        }
        
        
        $this->error  = null;
        $this->json  = true;
        $this->action = 'default';
        $this->template = null;
        
        $this->updaterCheck();
    }
    
    function getOutput() {
        if ($this->error == 'unknown') {
            global $messageStack;
            $message = tep_not_null($messageStack->errors) ? strip_tags($messageStack->errors[0]['text']) : '';
            $message = strtr($message, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)));
            $message = trim($message, chr(0xC2).chr(0xA0));
            
            $this->output = $message . (tep_not_null($this->output) ? ' - ' . $this->output : '');  
        }
        //global $messageStack;
        //$messageStack->add_session(implode(" == ", array('action'=>$this->action, 'error'=>$this->error, 'output'=>$this->output, 'time'=>time())));
        $retval = array('action'=>$this->action, 'error'=>$this->error, 'output'=>$this->output, 'time'=>time());
        return $retval;
    }
    
    function jsonHeader($header=true) {
        $this->json = $header;
    }
    
    function jsonOutput() {
        $output = $this->getOutput();
        header("Cache-Control: private");
        if ($this->json) {
            header('Content-type: application/json');
            echo json_encode($output);
        } else {
            header('Content-type: text/html');
            echo '<html><head><title>Uploader</title>'."\n";
            echo '<script type="text/javascript"><!--'."\n";
            echo " window.output='".json_encode($output)."';\n";
            echo '</script>'."\n";
            echo '</head><body>'.time().'</body></html>';
        }
    }
    
    function cleanUp() {
        if (OSC_PRODUCT_IMAGE_CLEANUP == 'true') {
            tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='false', last_modified=NOW() WHERE configuration_key='OSC_PRODUCT_IMAGE_CLEANUP'");
            
            if (tep_not_null($this->options['thumbnail_dir'])) {
                $dir = $this->options['upload_dir'] . $this->options['thumbnail_dir'];
                $dir = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dir);
                $this->_cleanUpThumbnail($dir);
            }
        }
    }
    
    function getDirectories() {
        global $opi_directories;
        $this->action = 'getDirectories';
        
        $this->directories = array();
        if (tep_session_is_registered('opi_directories') && is_array($opi_directories)) {
            $this->directories = $opi_directories;
        } else {
            $dir = $this->options['upload_dir'] . $this->options['relative_dir'];
            $this->output = $dir;
            
            if (!is_dir($dir)) {
                $this->error = 'error_not_exist';
                $this->output = OPI_WARNING_DIRECTORY_NOT_EXIST;
            } elseif (!is_readable($dir)) {
                $this->error = 'error_not_readable';
            } else {
                $this->directories[""] = "/";
                $this->_readDirectory();
                $opi_directories = $this->directories;
                
                if (!tep_session_is_registered('opi_directories')) tep_session_register('opi_directories');
            }
        }
        
        if (!$this->error) {
            header("Last-Modified: " . gmdate("D, d M Y H:i:s", OSC_PRODUCT_IMAGE_MODULE_UPDATER) . " GMT");
            $this->output = array_keys($this->directories);
        }
    }

    
    private function _readDirectory($folder='') {
        $dir = $this->options['upload_dir'] . $this->options['relative_dir'] . $folder;
        $dir = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dir);
        
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if (preg_match("@^[a-z0-9]@i", $file) && is_dir($dir.$file) && is_readable($dir.$file)) {
                        $this->directories[$folder.$file.'/'] = $file;
                        $this->_readDirectory($folder.$file.'/');
                    }
                }
                closedir($dh);
            }
        }
    }
    
    function createDirectory() {
        global $admin;
        $this->action = 'createDirectory';
        
        $new_folder = isset($_POST['opi_directory']) ? trim(strtolower(strip_tags($_POST['opi_directory']))) : null;
        $opi_folder = isset($_POST['opi_folder']) ? strip_tags($_POST['opi_folder']) : '';
        
        $directory_privileges = explode(',', OSC_PRODUCT_IMAGE_DIRECTORY_PRIVILEGE);
        $has_directory_privileges = tep_not_null($directory_privileges) ? (in_array($admin['id'], $directory_privileges) ? 1 : 0) : 1;

        $dest = $this->options['upload_dir'].$this->options['relative_dir'].$opi_folder;
        $dest = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dest);
        
        $this->output = $new_folder;
        $this->error  = 0;
        
        if (!tep_not_null($new_folder) || strlen($new_folder) < 4) {
            $this->error = 'error_create_empty';
        } elseif (preg_match("@[^a-z0-9]@i", $new_folder)) {
            $this->error = 'error_create_alphanumeric';
        } elseif (!preg_match("@^[a-z0-9]@i", $new_folder)) {
            $this->error = 'error_create_character';
        } elseif (!$has_directory_privileges) {
            $this->error = 'error_create_privilege';
        } elseif (!is_dir($dest)) {
            $this->error = 'error_not_exist';
        } elseif (!is_writable($dest)) {
            $this->error = 'error_not_writable';
        } elseif (file_exists($dest . $new_folder)) {
            $this->error = 'error_create_exist';
        }
        
        if (!$this->error) {
            if (mkdir($dest . $new_folder)) {
                $this->error = 0;
            } else {
                global $messageStack;
                $messageStack->add('Error creating directory at: ' .$dest);
                //$messageStack->add_session('Error creating directory at: ' .$dest);
                $this->error = 'unknown';
            }
        }
    }
    
    function browseFiles() {
        $this->action = 'browseFiles';
        
        $opi_browse = isset($_POST['opi_folder']) ? strip_tags($_POST['opi_folder']) : '';
        $dir = $this->options['upload_dir'].$this->options['relative_dir'].$opi_browse;
        $dir = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dir);
        
        if (!tep_session_is_registered('opi_browse')) {
            tep_session_register('opi_browse');
        }
        
        
        $this->output = $opi_browse;
        if (!is_dir($dir)) {
            $this->error = 'error_not_exist';
        } elseif (!is_readable($dir)) {
            $this->error = 'error_not_readable';
        }
        
        if ($this->error) return;
        
        if ($dh = @opendir($dir)) {
            $files = array();
            while (($file = @readdir($dh)) !== false) {
                if (preg_match("@^[a-z0-9]@i", $file)) {
                    if (preg_match('@\.('.$this->options['extensions'].')$@i', $file)) {
                        $files[] = $this->options['relative_dir'].$opi_browse.$file;
                    }
                }
            }
            closedir($dh);
            $this->output = $files;
        } else {
            $this->error = 'error_not_readable';
        }
    }
    
    function delete() {
        global $admin;
        
        $this->action = 'delete';
        
        $delete_privileges = explode(',', OSC_PRODUCT_IMAGE_DELETE_PRIVILEGE);
        $has_delete_privileges = tep_not_null($delete_privileges) ? (in_array($admin['id'], $delete_privileges) ? 1 : 0) : 1;
        
        
        $file = isset($_POST['opi_delete']) ? strip_tags($_POST['opi_delete']) : '';
        $dest = $this->options['upload_dir'].$file;
        $dest = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dest);
        $bFile = basename($dest);
        
        $this->output = $bFile;
        
        if (!tep_not_null($file)) {
            $this->error = 'error_delete_empty';
        } elseif (!preg_match('@\.('.$this->options['extensions'].')$@i', $bFile)) {
            $this->error = 'error_file_extension';
        } elseif (!$has_delete_privileges) {
            $this->error = 'error_delete_privilege';
        } elseif ($this->_deleteCheck($file)) {
            $this->error = 'error_delete_in_use';
        } elseif (!is_dir(dirname($dest))) {
            $this->error = 'error_not_exist';
            $this->output = dirname($dest);
        } elseif (!is_writable(dirname($dest))) {
            $this->error = 'error_delete_global';
            $this->output = dirname($dest);
        }
        
        if (!$this->error) {
            if (unlink($dest)) {
                $this->error = 0;
                $this->_cleanUpImage($file);
            } else {
                global $messageStack;
                $messageStack->add_session("Can not delete: " . $dest);
                $this->error = 'unknown';
            }
        }
    }
    
    private function _deleteCheck($file) {
        $counts_query = tep_db_query("SELECT COUNT(*) as total FROM " . TABLE_PRODUCTS . " WHERE products_image='".tep_db_input($file)."' OR FIND_IN_SET('".tep_db_input($file)."', products_images)");
        $counts_fetch = tep_db_fetch_array($counts_query);
        return (intval($counts_fetch['total']) > 0);
    }
        
    
    function upload() {
        $this->action = 'upload';
        
        $upload_folder = isset($_POST['opi_folder']) ? strip_tags($_POST['opi_folder']) : '';
        $dest = $this->options['upload_dir'].$this->options['relative_dir'].$upload_folder;
        $dest = preg_replace('@[\/\\\]@', DIRECTORY_SEPARATOR, $dest);

        $this->output = $upload_folder;
        
        if (!is_dir($dest)) {
            $this->error = 'error_not_exist';
            $this->output = dirname($dest);
        } elseif (!is_writable($dest)) {
            $this->error = 'error_not_writable';
            $this->output = dirname($dest);
        }
        
        if ($this->error) return;
        
        $upload = new upload('opi_upload');
        $upload->set_destination($dest);
        if ($upload->parse() && $upload->save()) {
            if (strtolower($upload->filename) !== $upload->filename) {
                if (@rename($dest.$upload->filename, $dest.strtolower($upload->filename))) {
                    $upload->filename = strtolower($upload->filename);
                }
            }
            $this->output = $this->options['relative_dir'].$upload_folder.$upload->filename;
            
            
            if (isset($_POST['opi_auto_rename']) && $_POST['opi_auto_rename'] == '1') {
            $paths = pathinfo($dest.strtolower($upload->filename));
            $rename= $upload->filename;
                if (isset($_POST['opi_rename']) && tep_not_null($_POST['opi_rename'])) {
                    $rename = strtolower(preg_replace(array("@[^0-9a-z]+@i","@^[^0-9a-z]+@i","@[^0-9a-z]+$@i"), array("-","",""), $_POST['opi_rename']));
                }
            
                if (basename($upload->filename) != basename($rename)) {
                    $newname = $rename . '.' . $paths['extension'];
                    $n = 0;
                    while(file_exists($dest.$newname)) {
                        $n++;
                        $newname = $rename . '-' . $n . '.' . $paths['extension'];
                    }
                    if (@rename($dest.$upload->filename, $dest.$newname)) {
                        $upload->filename = $newname;
                    }
                }
                $this->output = $this->options['relative_dir'].$upload_folder.$upload->filename;
            }
            $this->updater();
        } else {
            $this->error = 'unknown';
        }
    }
    
    function setTemplate($pInfoProductsImages) {
        global $languages_id, $admin, $SESS_LIFE;
        
        $directory_privileges = explode(',', OSC_PRODUCT_IMAGE_DIRECTORY_PRIVILEGE);
        $has_directory_privileges = tep_not_null($directory_privileges) ? (in_array($admin['id'], $directory_privileges) ? 1 : 0) : 1;
        $delete_privileges = explode(',', OSC_PRODUCT_IMAGE_DELETE_PRIVILEGE);
        $has_delete_privileges = tep_not_null($delete_privileges) ? (in_array($admin['id'], $delete_privileges) ? 1 : 0) : 1;

        $relative_catalog_image = preg_replace('@^'.DIR_WS_CATALOG.'@i', '', DIR_WS_CATALOG_IMAGES);
        
        if (!defined('OPI_HELPER_LANGUAGE_ID'))     define('OPI_HELPER_LANGUAGE_ID', $languages_id);
        if (!defined('OPI_HELPER_SESSION_LIFE'))    define('OPI_HELPER_SESSION_LIFE', $SESS_LIFE*1000);
        if (!defined('OPI_HELPER_PRODUCTS_IMAGES')) define('OPI_HELPER_PRODUCTS_IMAGES', $pInfoProductsImages);
        if (!defined('OPI_HELPER_CATALOG_IMAGES'))  define('OPI_HELPER_CATALOG_IMAGES', tep_catalog_href_link($relative_catalog_image));
        if (!defined('OPI_HELPER_RELATIVE_DIR'))    define('OPI_HELPER_RELATIVE_DIR', $this->options['relative_dir']);
        if (!defined('OPI_HELPER_ALLOWED_EXT'))     define('OPI_HELPER_ALLOWED_EXT', $this->options['extensions']);
        if (!defined('OPI_HELPER_DIR_PRIVILEGE'))   define('OPI_HELPER_DIR_PRIVILEGE', $has_directory_privileges);
        if (!defined('OPI_HELPER_DEL_PRIVILEGE'))   define('OPI_HELPER_DEL_PRIVILEGE', $has_delete_privileges);
        
        //get template
        ob_start();
        include (DIR_WS_CLASSES . "productImageHandlerTpl.inc");
        $this->template = ob_get_contents();
        ob_end_clean();
        
        return $this->template;
    }
    
    function printTemplate($pInfoProductsImages='') {
        if (!tep_not_null($this->template))
            $this->setTemplate($pInfoProductsImages);
        
        echo $this->template;
    }
    
    function updaterCheck() {
        global $opi_updater, $opi_directories, $opi_relative_dir;
        if (!tep_session_is_registered('opi_updater')) {
            $opi_updater = 0;
        }
        if (!tep_session_is_registered('opi_relative_dir')) {
            $opi_relative_dir = $this->options['relative_dir'];
        }
        
        if ($opi_updater < OSC_PRODUCT_IMAGE_MODULE_UPDATER || $this->options['relative_dir'] != $opi_relative_dir) {
            $opi_updater = OSC_PRODUCT_IMAGE_MODULE_UPDATER;
            $opi_relative_dir = $this->options['relative_dir'];
            $opi_directories = null;
            //$opi_browse = '';
            return false;
        }
        return true;
    }
    
    function updater() {
        clearstatcache();
        tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='".time()."', last_modified=NOW() WHERE configuration_key='OSC_PRODUCT_IMAGE_MODULE_UPDATER'");
    }
    
    private function _cleanUpThumbnail($dir) {
        if (is_dir($dir) && !is_link($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if (strlen($file) > 2 && strpos($file, '.') !== 0 && !is_link($file)) {
                        if (is_dir($dir.$file)) {
                            if ($file != '.' && $file != '..') { //double check
                                $this->_cleanUpThumbnail($dir.$file.DIRECTORY_SEPARATOR);
                                @rmdir($dir.$file);
                            }
                        } else {
                            @unlink($dir.$file);
                        }
                    }
                }
                closedir($dh);
            }
        }
    }
    
    private function _cleanUpImage($image) {
        global $messageStack;
        $dir = $this->options['upload_dir'] . $this->options['thumbnail_dir'];
        $messageStack->add_session($dir);
        
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file = readdir($dh)) !== false) {
                    if (is_dir($dir.$file) && $file != '.' && $file != '..') {
                        if (file_exists($dir.$file.DIRECTORY_SEPARATOR.$image)) {
                            @unlink($dir.$file.DIRECTORY_SEPARATOR.$image);
                        }
                    }
                }
                closedir($dh);
            }
        }
    }
    
    function debug() {
        global $messageStack;
        $debug = 'ACTION='.$this->action . ":\n";
        $debug .= "\n".'GET::';
        while(list($key,$value)=each($_GET)) {
            $debug .= "\n" . $key . '=' . (is_array($value) ? implode(',', $value) : $value);
        }
        $debug .= "\n".'POST::';
        while(list($key,$value)=each($_POST)) {
            $debug .= "\n" . $key . '=' . (is_array($value) ? implode(',', $value) : $value);
        }
        $debug .= "\n".'FILE::';
        while(list($key,$value)=each($_FILE)) {
            $debug .= "\n" . $key . '=' . (is_array($value) ? implode(',', $value) : $value);
        }
        tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='".tep_db_input($debug)."', last_modified=NOW() WHERE configuration_key='OSC_PRODUCT_IMAGE_MODULE_DEBUGER'");
        
        $messageStack->add_session(nl2br($debug));
    }
  }
  
  function opiCleanUpThumbnail() {
      //
  }
?>